<template>
  <view class="content">
    <form action="" class="form" @submit="loginsubmit">
      
      <view class="uni-form-item uni-column">
        <input class="uni-input" name="userMobile" v-model="userMobile" maxlength="16" placeholder="请输入用户名" />
      </view>
      <view class="uni-form-item uni-column">
        <input class="uni-input" name="userPassword" type="password" maxlength="15" v-model="userPassword" placeholder="请输入密码" />
      </view>

      <view class="addr">
        <view></view>
        <view><a style="margin-left: 10rpx;">找回密码</a></view>
      </view>
      <view class="uni-btn-v">
        <button form-type="submit" class="submit">登录</button>
      </view>
      <view class="copyright">
        <text> 胜利镇农产品系统</text>
      </view>
    </form>
  </view>
</template>

<script>
  // 引入API
  import {_config} from '@/config'
  import { login } from '@/api/teacher.js';
  
  export default {
    data() {
      return {
        userMobile:'',
        userPassword: '',
        back: false,
      }
    },
    watch: {
      
    },
    onLoad(option){
      if (typeof option.back != 'undefined') {
        this.back = true;
      }
    },
    onBackPress(option) {
      if (option.from == 'backbutton' && !this.back) {
        uni.switchTab({
          url:'../index/index'
        })
        return true;
      }
    },
    methods: {
      
      loginsubmit(data) {
        if (this.userMobile.length<1) {
          uni.showToast({
            title: '请输入用户名',
            icon : 'none',
          });
          return;
        }
        if (this.userPassword.length<1) {
          uni.showToast({
            title: '请输入登录密码',
            icon : 'none',
          });
          return;
        }
        let loginData = data.detail.value;
        login(loginData).then(res => {
          if (res.data.code == 0) {
            let data = res.data.data;
            console.log(data)
            uni.setStorageSync("token", data.Token);
            uni.setStorageSync("teacherdataid", data.TeacherDataID);
            uni.setStorageSync("teachername", data.TeacherName);
            uni.setStorageSync("usermobile", data.UserMobile);
            uni.switchTab({
              url: '/pages/my/details/details'
            })
          } else {
            uni.showToast({
              title: res.data.msg,
              icon : 'none',
            });
          }
        });
      },
      clickLink(link){
        let url = './' + link;
        uni.navigateTo({
          url: url
        })
      },
      
    }
  }
</script>

<style>
page {
  width: 100%;
  height: 100%;
}
.content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background-image: url('/static/images/4.png'); /* 添加背景图片 */
  background-size: cover; /* 背景图片覆盖整个容器 */
  background-position: center; /* 背景图片居中 */
}
.logo {
  width: 320rpx;
  height: 150rpx;
  margin-bottom: 80rpx;
}
.form {
  height: 700rpx;
  width: 90%;
  background-color: transparent; /* 设置为透明背景 */
  border-radius: 10rpx; /* 添加圆角 */
  box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1); /* 添加阴影 */
}
.uni-input {
  height: 120rpx;
  border-bottom: 1px solid #ccc;
  margin: 10rpx 0;
  font-size: 34rpx;
}
.uni-column {
  position: relative;
}

.uni-btn-v {
  margin: 20rpx 0;
}
.submit {
  font-size: 36rpx;
  background-image: linear-gradient( #60A0D4, #60A0D4);
  color: #FFFFFF;
}
.addr {
  display: flex;
  justify-content: space-between;
  margin: 20rpx 0;
  color: #60A0D4;
}
.copyright {
  position: fixed;
  font-size: 45rpx;
  color: #red;
  width: 90%;
  text-align: center;
  padding: 00rpx 0rpx;
}
</style>